package com.java.web.manageweb.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.java.manage.pojo.TbItem;
import com.java.manage.pojo.TbItemCat;
import com.java.manage.service.TbItemCatService;
import com.java.manage.service.TbItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
/**
 *  菜单事件
 *
 * @author Tigger Wu
 * @date 2018/9/7 14:31
 */
@Controller
@RequestMapping("/rest/item/cat")
public class ItemCatController {
    @Autowired
    private TbItemCatService item;
    /**
     *  查询商品列表
     *
     * @author Tigger Wu
     * @date 2018/9/7 14:32
     * @param id
     * @return org.springframework.http.ResponseEntity<java.util.List<com.java.manage.pojo.TbItemCat>>
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<List<TbItemCat>> queryItemListByParentId(@RequestParam(value = "id",defaultValue = "0")Integer id){
        try{
            EntityWrapper<TbItemCat> wrapper = new EntityWrapper<TbItemCat>();
            wrapper.where("parent_id ={0}",id);
            List<TbItemCat> cats = item.selectList(wrapper);
            if(cats ==null||cats.isEmpty()){
                return  ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            return ResponseEntity.ok(cats);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

}
